<?php


##-----------------------------------------------------------------------------____________________ADMIN_LOGIN_FORM


function ADMIN_LOGIN_FORM(){


?>


	<br><br><br><br>


	<center>


	<form method="post" action="admin.php">


		<table border="1">


			<tr>


				<td>نام کاربری : </td>


				<td><input type="text" name="aUSER" ></td>


			</tr>


			<tr>


				<td>رمز عبور: </td>


				<td><input type="password" name="aPASS" ></td>


			</tr>


			<tr>


				<td align="center" colspan="2"><input type="submit" value="Login"></td>


			</tr>


		</table>


	</form>


	</center>

<?php


}


##-----------------------------------------------------------------------------____________________ADMIN_LOGIN_FORM


function ADMIN_LOGIN($aUSER,$aPASS){

	db();

	if(!$sql=mysql_query(" select * from P30vel_admin where 1 and username='$aUSER' and password='$aPASS' limit 1 "))


		{ERROR("Invalid Username or Password");die();}

	if(mysql_num_rows($sql)!=1)return false;


	$_SESSION['aUSER']=$aUSER;


	$_SESSION['aPASS']=$aPASS;


	return true;	

}


##-----------------------------------------------------------------------------____________________ADMIN_LOGOUT


function ADMIN_LOGOUT(){



	$_SESSION['aUSER'] = false;


	$_SESSION['aPASS'] = false;


	unset($_SESSION['aUSER']);


	unset($_SESSION['aPASS']);


	if($_SESSION['aUSER'] || $_SESSION['aPASS'])


		{echo "Unable to logout.";return false;}


	return true;

}



##-----------------------------------------------------------------------------____________________ADMIN_LINKBAR


function ADMIN_LINKBAR(){


?>	

	<table cellpadding="3" cellspacing="1" bgcolor="#c6c6c6" width="80%" align="center" border="0" style="font-size:12px; font-family:tahoma; ">


		<tr bgcolor="#f0f0f0">


			<td align="center" width="120"><a style="color:#53727e; text-decoration:none;" href="admin.php">ليست همه پرداختها</a></td>


			<td align="center" width="120"><a style="color:#53727e; text-decoration:none;" href="admin.php?ACT=CHANGEPASS">تغيير رمز عبور</a></td>


			<th>&nbsp;</th>


			<th width="120"><a style="color:#53727e; text-decoration:none;" href="admin.php?ACT=LOGOUT"><b>خروج</b></a></th>


		</tr>


	</table>


<?php	


}

##-----------------------------------------------------------------------------____________________LIST_ARCHIVE

function LIST_ARCHIVE(){

	db();


	$tdd=10;


	$stt=$tdd*GTPT('PaG');


	switch(GTPT('ACT')){


		case 'DELL' :


			EPAY_DELL(GTPT('batch_number'));


			break;


		case 'EDIT' :


			EPAY_EDIT(GTPT('batch_number'));


			return true;


			break;

	}


	//DELETE_NUN_BATCH_RECORDS();


	if(!$sql=mysql_query(" select * from epay where 1 and not ( batch_number like 'BATCH:FOR:%' )   order by pay_date desc   limit $stt,$tdd "))

		{ERROR("Error in progress");return false;}


	?>


	<br>


	<form name="aFORM" method="post" action="admin.php">


	<input type="hidden" name="ACT" value="EDIT" >


	<input type="hidden" name="batch_number" value="" >

	<center>


	<table dir="rtl" style="font-size:12px; font-family:tahoma;" width="80%" cellpadding="2" cellspacing="1" border="0" bgcolor="#57b151">


		<tr bgcolor="#aec6ac">


			<th>شماره سريال</th>


			<th>سبب تراکنش</th>


			<th>پرداخت کننده</th>


			<th>مبلغ تراکنش (ريال)</th>


			<th>تاريخ پرداخت</th>


			<th>---</th>


		</tr>


	<?php

	for($i=0; $i<mysql_num_rows($sql); $i++){


		$row=mysql_fetch_array($sql);


		echo "


			<tr bgcolor='#edffe3'>


				<td>".$row['batch_number']."</td>


				<td>".$row['memo']."</td>


				<td>".$row['pay_from']."</td>


				<td>".$row['pay_value']." </td>


				<td>".substr(U2Vaght($row['pay_date']),0,10)."</td>


				<td width=50 align=center >


					<a title='ويرايش' href='javascript:aFORM.batch_number.value=\"".$row['batch_number']."\"; aFORM.submit();'><img border=0 src='img/edit.gif'></a>


				</td>


			</tr>


		";


	}


	?>


	<tr>


			<td colspan="5" align="center">


	<?php


	$mysqlnumrows=mysql_num_rows($sql);


	$PG=($mysqlnumrows-$mysqlnumrows%$tdd)/$tdd;


	if($mysqlnumrows%$tdd)$PG++;


	for($x=0; $x<$PG; $x++)


		if($x==GTPT('PaG'))echo "<b>".($x+1)."</b> ";


		else echo "<a href='admin.php?ACT=LIST_ARCHIVE&PaG=$x' >".($x+1)."</a> ";


	?>


	</td>


		</tr>

	</table>


	</center>


	</form>


	<?php

}


##-----------------------------------------------------------------------------____________________EPAY_EDIT


function EPAY_EDIT($batch_number=''){


	db();

	if(!$batch_number){ERROR("<br>No record found");return false;}


	if(!$sql=mysql_query(" select * from epay where 1 and batch_number='$batch_number'    limit 1 "))


		{ERROR("Invalid MySQL");return false;}


	if(mysql_num_rows($sql)>1){ERROR("Error in progress");return false;}

	if(mysql_num_rows($sql)==1)


		if(!$row=mysql_fetch_array($sql))


			{ERROR("Error in progress");return false;}

	if(mysql_num_rows($sql)==0)


		$addSTR="

		<br>

		تراکنش قبلاً ثبت نشده. لطفاً مشخصات را کامل، و تأييد کنيد


		";

	if(!$VERIFY_RESULT=VERIFY_PROCCES($batch_number,$GLOBALS['MID'],"OK")){

		echo "

		<br><br><br><br>


		<center>


		<table width=400 height=40 cellpadding=2 cellspacing=1 bgcolor='#936b1a'><tr><td bgcolor='#ffe8db' style='font-family:tahoma; font-size:12px; color:#8b643b; ' align=center >


		پاسخ بانک : <b>تراکنشي با اين رسيد ديجيتالي ثبت نشده</b>


		<br>


		<form method='post' action='admin.php'>


		<input type='hidden' name='ACT' value='DELL' >


		<input type='hidden' name='batch_number' value='$batch_number' >


		<input type='submit' value='حذف از ليست پرداختها' >


		</form>


		<br>


		</td></tr></table>


		</center>


		<br><br>	


		";	


		return false;	


	}


	if($VERIFY_RESULT!=$row['pay_value']){


		echo "


		<br><br><br><br>


		<center>


		<table width=400 height=40 cellpadding=2 cellspacing=1 bgcolor='#936b1a'><tr><td bgcolor='#ffe8db' style='font-family:tahoma; font-size:12px; color:#8b643b; ' align=center >


		پاسخ بانک : <b>مبلغ پرداختي با مبلغ ثبت شده در بانک مطابقت ندارد</b>


		<br>


		<form method='post' action='admin.php'>


		<input type='hidden' name='ACT' value='DELL' >


		<input type='hidden' name='batch_number' value='$batch_number' >


		<input type='submit' value='حذف از ليست پرداختها' >


		</form>


		<br>


		</td></tr></table>


		</center>


		<br><br>


		";	


		return false;


	}


	?>


	<form method="post" action="admin.php">


	<input type="hidden" name="ACT" value="SAVE_EDIT">


	<input type="hidden" name="batch_number" value="<?=$batch_number ?>">


	<input type="hidden" name="pay_value" value="<?=$VERIFY_RESULT ?>">


	<center><br>


	<table dir="rtl" width="80%" style='font-family:tahoma; font-size:12px;' cellpadding="2" cellspacing="1" bgcolor="#c2dcdf">


		<tr height="1" bgcolor="#acb2b5"><td colspan="2" align="center"></td></tr>		


		<tr height="35"><td colspan="2" align="center">ويرايش پرداختها</td></tr>		


		<tr height="1" bgcolor="#acb2b5"><td colspan="2" align="center"></td></tr>		


		<tr bgcolor="#f4ffff">


			<td>شماره سريال:</td>


			<td><input style="font-size:12px; font-family:tahoma;" disabled type="text" name="batch_number" value="<?=$batch_number ?>"></td>


		</tr>		


		<tr bgcolor="#f4ffff">


			<td>مبلغ پرداخت (به ريال):</td>


			<td><input style="font-size:12px; font-family:tahoma;" disabled type="text" name="pay_value" value="<?=$VERIFY_RESULT ?>"></td>


		</tr>

		<tr bgcolor="#f4ffff">


			<td>نام پرداخت کننده:</td>


			<td><input style="font-size:12px; font-family:tahoma;" type="text" name="pay_from" value="<?=$row['pay_from'] ?>"></td>


		</tr>


		<tr bgcolor="#f4ffff">


			<td>سبب تراکنش:</td>


			<td><input style="font-size:12px; font-family:tahoma;" type="text" name="memo" value="<?=$row['memo'] ?>"></td>


		</tr>

		<tr height="1" bgcolor="#acb2b5"><td colspan="2" align="center"></td></tr>		


		<tr height="35">


			<td colspan="2" align="center">


				<input style="font-size:12px; font-family:tahoma; background-color:white;" type="submit" value="ثبت تغييرات">


				<input style="font-size:12px; font-family:tahoma; background-color:white;" type="button" onclick="if(confirm('آيا مايل به بازگشت کامل تراکنش هستيد؟'))location.href='admin.php?ACT=REJECT&batch_number=<?=$batch_number ?>'" value="برگشت تراکنش">


			</td>


		</tr>


		<tr height="1" bgcolor="#acb2b5"><td colspan="2" align="center"></td></tr>		

	</table>


	</center>

	</form>


	<?php

	echo "


	<center>


	<table width=400 height=40 cellpadding=2 cellspacing=1 bgcolor='#7c931a'><tr><td bgcolor='#f6fff0' style='font-family:tahoma; font-size:12px; color:#738b3b; ' align=center >


	پاسخ بانک : <b>تأييد شد</b>


	$addSTR


	</td></tr></table>


	</center>	


	";	

}


##-----------------------------------------------------------------------------____________________SAVE_EDIT

function SAVE_EDIT(){

	if(!$batch_number=$_POST['batch_number'])return false;


	db();

	if(!$sql=mysql_query(" select * from epay where 1 and batch_number='$batch_number' limit 1 "))


		{ERROR("Error in progress"); return false;}


	if(mysql_num_rows($sql)!=1){


		if(!$sql=mysql_query(" insert into epay 


			(res_num,batch_number,memo,pay_from,pay_value,pay_date) values 


			('".BRING_NEW_RES_NUM()."','".$_POST['batch_number']."','".$_POST['memo']."','".$_POST['pay_from']."','".$_POST['pay_value']."','".date("U")."') "))


			{ERROR("Error in progress"); return false;}


	}


	else {


		if(!$sql2=mysql_query(" update epay set 


			pay_from='".$_POST['pay_from']."'


			,memo='".$_POST['memo']."'


		where 1 and batch_number='$batch_number' limit 1 ")){ERROR("Error in security:310"); return false;}


	}


	return true;	


}


##-----------------------------------------------------------------------------____________________MINI_BATCH_FORM


function MINI_BATCH_FORM(){


?>


<form method="post" action="admin.php">


<input type="hidden" name="ACT" value="EDIT" >


	<center>


	<table style="font-size:12px; font-family:tahoma;" dir="rtl" bgcolor="#adced2" cellpadding="2" cellspacing="1"><tr><td bgcolor="#e9eff0" align="center">


	شماره سريال : <input type="text" style="font-size:12px; font-family:tahoma;" name="batch_number" >


	<input type="submit" value="جستجو" style="font-size:12px; font-family:tahoma;" >


	</td></tr></table>


	</center>


</form>

<?php


}


##-----------------------------------------------------------------------------____________________CHANGEPASS_FORM


function CHANGEPASS_FORM(){


?>	

<br><br><br><br><br><br><br>

	<center>

	<form name="psFORM" method="post" action="admin.php"onsubmit="


		if(psFORM.pass2.value!=psFORM.pass3.value){alert('Invalid password');return false;}


	">


	<input type="hidden" name="ACT" value="SAVEPASS" >


	<table bgcolor="#dbdfc6" cellpadding="2" cellspacing="1" style="font-size:12px; font-family:helvetica;color:#718222">

		<tr>


			<th colspan="2">Fill & Submit</th>


		</tr>

		<tr bgcolor="#fefff4">


			<td>Old password</td>


			<td><input type="password" name="pass1" ></td>


		</tr>


		<tr bgcolor="#fefff4">


			<td>New password</td>


			<td><input type="password" name="pass2" ></td>


		</tr>


		<tr bgcolor="#fefff4">


			<td>Repeat new password</td>


			<td><input type="password" name="pass3" ></td>


		</tr>


		<tr bgcolor="#fefff4" height="50">


			<td colspan="2" align="center" ><input type="submit" value="Save password" style="font-size:11px;" ></td>


		</tr>


	</table>


	</form>

	</center>

<?php	


}


##-----------------------------------------------------------------------------____________________SAVEPASS


function SAVEPASS(){


	db();


	if(!$sql=mysql_query(" select * from P30vel_admin where 1 and username='admin' limit 1 ")){echo "Invalid query";return false;}


	$admin=mysql_fetch_array($sql);


	if($admin['password']!=$_POST['pass1']){echo "Invalid password";return false;}


	if($_POST['pass2']!=$_POST['pass3']){echo "Invalid password";return false;}

	if(!$sql=mysql_query(" update P30vel_admin set password='".$_POST['pass2']."' where username='admin' limit 1 "))


		{echo "Invalid query2";return false;}

	$_SESSION['aUSER']='admin';


	$_SESSION['aPASS']=$_POST['pass2'];

	return true;	


}
